script(type='text/javascript')
	var newRow = function(id, name) {
		return '<tr><td class="neutral" colspan="2">' + name
			+ '<input type="button" value="Remove" onclick="$(this).parent().parent().remove()"/>'
			+ '<input type="hidden" name="inputs[]" value="' + id + '" />'
			+ '</td></tr>';
	};
	
	addInput = function() {
		$(newRow($("#inputs option:selected")[0].value,
			$("#inputs option:selected")[0].innerHTML)).insertAfter("#inputsHead");
	};

form(
	method='post',
	action='/link',
	enctype='application/x-www-form-urlencoded')
	table#editLink
		tr
			td.neutral(colspan='2')
				h3= title
				input(type='hidden', name='action', value= action)
				input(type='hidden', name='_id', value= link._id)
				input#save(type='submit',value='Save')
				input(type='button',onclick='window.location.href=\'/link/' + link._id + '/remove\'', value='Remove')
		tr
			td.neutral.editLabel Link Name
			td.neutral
				input(type='text',name='name',value=link.name)
		tr#inputsHead
			td.neutral(colspan='2')
				b Inputs
				select#inputs
					each port in ports
						option(value= port._id)= port.sysId
				input#editAddInput(
					type='button',
					value='Add Input',
					onclick='addInput()')			
		each input in link.inputs
			tr
				td(colspan='2').neutral= input.sysId
					input(type='hidden',name='inputs[]',value= input._id)
					input(type='button',value='Remove').link(onclick='$(this).parent().parent().remove()')
		tr
			td.neutral.editLabel Output
			td.neutral
				select(name='output')
					each port in ports
						option(value= port._id)= port.sysId
		tr
			td.neutral.editLabel Description
			td.neutral
				input(type='text',name='description',value=link.description)
		tr
			td.neutral.editLabel Relation
			td.neutral
				b function(inputs) {
				div(style='margin-left: 32px;')
					textarea(name='relation', rows='16', cols='48')= link.relation
					span return output;
				b }
